require "test/unit"

require "Pat"

class TestPat < Test::Unit::TestCase
  def test_assignment
     p = Pat.new
     p["1"] = "test"
     assert_equal("test", p["1"])
     
     p["2"] = "test2"
     assert_equal("test2", p["2"])
     
     p["1"] = "test3"
     assert_equal("test3", p["1"])
     
     assert_nil(p["nil"])
  end
  
  def test_clone
    p = Pat.new
    p1 = p.clone
    p["1"] = 1
    p1["2"] = 2
    assert_equal(p["1"], p1["1"])
    assert_equal(p1["2"], p["2"])
  end
  
  def test_lazy_clone
    p = Pat.new
    cl = p.lazy_clone
    assert_equal(cl.lazy_copy, true)
  end
  
  def test_parent
    p = Pat.new
    p["a"] = 1
    p1 = Pat.new(:parent => p)
    assert_equal(p["a"], p1["a"])
    
    p["b"] = 2
    assert_equal(p["b"], p1["b"])
    
    p2 = Pat.new(:parent => p1)
    assert_equal(p1["b"], p2["b"])
  end
end